package com.itheima.d2_byte_stream;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/*
     目标：使用字节流完成对文件的复制操作。
     数据源
     目的地
 */
public class CopyTest5 {
    public static void main(String[] args) throws Exception {
        long l = System.currentTimeMillis();
        copy1();
        long l1 = System.currentTimeMillis();
        System.out.println("复制文件花费时间："+(l1-l));


    }

    public static void copy1() throws IOException {
        FileInputStream fis = new FileInputStream("D:\\p图\\孙\\脸部.jpg");
        FileOutputStream fos = new FileOutputStream("a.jpg");

        int len;
        byte[] bytes = new byte[1024];
        while((len = fis.read(bytes)) != -1){
            fos.write(bytes, 0, len);
        }
        fos.close();
        fis.close();

    }
    public static void copy2() throws IOException {
        FileInputStream fis = new FileInputStream("D:\\p图\\孙\\脸部.jpg");
        FileOutputStream fos = new FileOutputStream("a.jpg");

        int len;
        while((len = fis.read()) != -1){
            fos.write(len);
        }
        fos.close();
        fis.close();

    }
}
